package com.friends.library.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.friends.library.persistence.HibernateUtil;

public class Renewal extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     * @author HAVE A NICE DAY
     */
    public Renewal() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int bookid=Integer.parseInt(request.getParameter("bookid"));
		String dateissued=request.getParameter("date");
		PrintWriter out=response.getWriter();
		Session session=HibernateUtil.getSessionFactory().openSession();
		Transaction transaction=session.beginTransaction();
		
		String s="update IssueBook set dateissued=:dateissued"+"where bookid=:bookid";
		Query query=session.createQuery("sql");
	
		query.setInteger("bookid",bookid);
		query.setString("dateissued",dateissued);
		int result=query.executeUpdate();
		if(result==1){
			response.sendRedirect("renewal.jsp");
		}else{
			out.println("<html><head></head><body><h2>Not Updated</h2></body></html>");
		}
		transaction.commit();
		session.close();
	}

}
